package com.rdtravel.converters;

import com.rdtravel.entities.DepartureLocation;
import com.rdtravel.services.DepartureLocationsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

public class StringToDepartureLocationConverter implements Converter<String, DepartureLocation> {
	private final DepartureLocationsService departureLocationsService;
	
	
	@Autowired
	public StringToDepartureLocationConverter(
			DepartureLocationsService departureLocationsService) {
		this.departureLocationsService = departureLocationsService;
	}



	@Override
	public DepartureLocation convert(String departureLocationName) {
		if (departureLocationName == null || departureLocationName.isEmpty()) {
			return null;
		}
		return departureLocationsService.findByName(departureLocationName);
	}
	

}
